from django.shortcuts import render, redirect

# Create your views here.
import re



###############################################
###############################################
remail = r'.^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$'


###############################################
###############################################

def index_view(request):
    return render(request, 'index_wel.html')


def login_view(request):
    username = request.POST.get('username')
    pwd = request.POST.get('pwd')
    print(username)
    print(pwd)

    if request.method == 'POST':
        if username == 'root' and pwd == '0000':
            return redirect('/superuser/admin/')
        elif username == 'group4' and pwd == '4444':
            return redirect('/customer/register_handle')
        else:
            return redirect('/customer/login')

    if request.method == 'GET':
        return render(request, 'index_login.html')


def main_view(request):
    return render(request, 'index.html')


def register_view(request):
    # 接收数据
    # username = request.POST.get('username')
    # email = request.POST.get('e-mail')
    # pwd = request.POST.get('pwd')
    # checkbox = request.POST.get('allow')
    # print(username)
    # print(pwd)
    # print(email)
    #
    # # 进行数据检验
    # if not all([username, email, pwd]):
    #     # 数据不完整
    #     return render(request, 'index_login.html', {'errmsg': 'Data is not complete!'})
    # if not re.match(remail, email):
    #     # 邮箱不合法
    #     return render(request, 'index_login.html', {'errmsg': 'Email Form is Not Allowed! '})
    # if checkbox != "on":
    #     # 未勾选checkbox
    #     return render(request, 'index_login.html', {'errmsg': 'Please agree the check box!'})

    # 业务处理

    # 返回应答
    return render(request, 'login_wel.html')


def horizontal_view(request):
    return render(request, 'index2.html')


def RTL_view(request):
    return render(request, 'dashboard-rtl.html')


def ecommerce_view(request):
    return render(request, 'ec-dashboard.html')


def blog_view(request):
    return render(request, 'blog-dashboard.html')


def appindex_view(request):
    return render(request, 'mail-inbox.html')


def chat_list(request):
    return render(request, 'chat.html')


def calendar_view(request):
    return render(request, 'events.html')


def file_view(request):
    return render(request, 'file-dashboard.html')


def connect_view(request):
    return render(request, 'contact.html')


def ecproduct_view(request):
    return render(request, 'ec-product.html')


def ecproductlist_view(request):
    return render(request, 'ec-product-List.html')


def ecproductdetail_view(request):
    return render(request, 'ec-product-detail.html')


def tables_view(request):
    return render(request, 'tables.html')


def tables_view(request):
    return render(request, 'tables.html')


def tables_view(request):
    return render(request, 'tables.html')


def tables_view(request):
    return render(request, 'tables.html')


def tables_view(request):
    return render(request, 'tables.html')
